<?php

class AjaxController extends Controller {
    public function actionSendGuestBook() {
        if (Yii::app()->user->isGuest) {
            return $this->_response(array('message' => 'Vui lòng đăng nhập để sử dụng tính năng này'));
        }
        $content = $_POST['content'];
        $owner_id = $_POST['owner_id'];
        $guestBook = new GuestBook();
        $guestBook->owner_id = $owner_id;
        $guestBook->post_time = time();
        $guestBook->poster_id = Yii::app()->user->id;
        $guestBook->content = $content;
        $user = UserBack::model()->findByPk(Yii::app()->user->id);
        $guestBook->poster_name = $user->user_name;
        $guestBook->save();


        return $this->_response($guestBook);

    }


    public function actionCheckLogin() {
        $name = $_POST['name'];
        $cat_id = $_POST['cat_id'];

        $arr = array('product_name' => $name, 'cat_id' => $cat_id);
        Yii::app()->session->add('up_product', $arr);

//        if (Yii::app()->user->isGuest) {
//            return $this->_response(array('url' => TreTodayUrl::getLoginUrl()));
//        } else {
        return $this->_response(array('url' => TreTodayUrl::getUpProductUrl()));
//        }
    }
}
